<template>
  <div>
    <div id="saledog">
      <img :src="imgurl" alt="" />
      <p :style="{ background: str }" @click="changecolor">{{ dogname }}</p>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      str: "",
    };
  },
  props: ["imgurl", "dogname"],
  methods: {
    changecolor() {
      this.str = `rgb(${Math.floor(Math.random() * 256)},${Math.floor(
        Math.random() * 256
      )},${Math.floor(Math.random() * 256)})`;
      this.$emit("love", this.dogname);
    },
  },
};
</script>

<style>
#saledog {
  width: 300px;
  height: 450px;
  float: left;
}
#saledog img {
  width: 100%;
  height: 200px;
}
#saledog p {
  text-align: center;
}
</style>